package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.IfCanCloseAccountBean;
import com.ymatou.iapi.userservice.parameter.req.CreateThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.CreateThirdPartyUserCall;
import com.ymatou.iapi.userservice.service.IfCanCloseAccountCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*检查是否可以注销
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_IfCanCloseAccount{
	private static IfCanCloseAccountBean ifcancloseaccountBean;
	private static IfCanCloseAccountCall ifcancloseaccountCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("检查是否可以注销");
	}

	@Before
	public void caseUp() {
		ifcancloseaccountBean=new IfCanCloseAccountBean();
		ifcancloseaccountCall=new IfCanCloseAccountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(ifcancloseaccountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_IfCanCloseAccount_001() {
		Logger.start(true,"检查是否可以注销30天内无记录,成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			ifcancloseaccountBean.setUserId(uid);
			ifcancloseaccountCall.setData(ifcancloseaccountBean);
			ifcancloseaccountCall.callService();			
			Logger.verifyEquals("true", ifcancloseaccountCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", ifcancloseaccountCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", ifcancloseaccountCall.getString("Result"), "验证Result");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_IfCanCloseAccount_002() {
		Logger.start(true,"不输入uid失败");
		try {
			ifcancloseaccountCall.setData(ifcancloseaccountBean);
			ifcancloseaccountCall.callService();			
			Logger.verifyEquals("false", ifcancloseaccountCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", ifcancloseaccountCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", ifcancloseaccountCall.getString("Result"), "验证Result");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_IfCanCloseAccount_003() {
		Logger.start(true,"30天内用户修改过登入密码,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			JUserCallService.UpdateLoginPwd(uid, "654321aB");
			ifcancloseaccountBean.setUserId(uid);
			ifcancloseaccountCall.setData(ifcancloseaccountBean);
			ifcancloseaccountCall.callService();			
			Logger.verifyEquals("true", ifcancloseaccountCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", ifcancloseaccountCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", ifcancloseaccountCall.getString("Result"), "验证Result");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_IfCanCloseAccount_004() {
		Logger.start(true,"30天内用户修改过交易密码,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			JUserCallService.UpdateTradingPwd(uid, "654321a");
			ifcancloseaccountBean.setUserId(uid);
			ifcancloseaccountCall.setData(ifcancloseaccountBean);
			ifcancloseaccountCall.callService();			
			Logger.verifyEquals("true", ifcancloseaccountCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", ifcancloseaccountCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", ifcancloseaccountCall.getString("Result"), "验证Result");
				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_IfCanCloseAccount_005() {
		Logger.start(true,"30天内用户修改过手机,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			JUserCallService.resetMobile(uid, cur.getMobile(), TestDataManager.getPhoneNum());
			ifcancloseaccountBean.setUserId(uid);
			ifcancloseaccountCall.setData(ifcancloseaccountBean);
			ifcancloseaccountCall.callService();			
			Logger.verifyEquals("true", ifcancloseaccountCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", ifcancloseaccountCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", ifcancloseaccountCall.getString("Result"), "验证Result");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_IfCanCloseAccount_006() {
		Logger.start(true,"30天内用户修改过邮箱,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			JUserCallService.resetMail(uid, TestDataManager.getEmail());
			ifcancloseaccountBean.setUserId(uid);
			ifcancloseaccountCall.setData(ifcancloseaccountBean);
			ifcancloseaccountCall.callService();			
			Logger.verifyEquals("true", ifcancloseaccountCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", ifcancloseaccountCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", ifcancloseaccountCall.getString("Result"), "验证Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_IfCanCloseAccount_007() {
		Logger.start(true,"30天内用户修改过第三方绑定解绑,失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer uid = urrc.getUserid();
			String token=urrc.getAccessToken();
			JUserCallService.bindWeiXinUseroRequestDto(JUserCallService.initBindWeiXinUseroRequestDtoBean(token));
			ifcancloseaccountBean.setUserId(uid);
			ifcancloseaccountCall.setData(ifcancloseaccountBean);
			ifcancloseaccountCall.callService();			
			Logger.verifyEquals("true", ifcancloseaccountCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", ifcancloseaccountCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", ifcancloseaccountCall.getString("Result"), "验证Result");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_IfCanCloseAccount_008() {
		Logger.start(true,"检查是否可以注销30天内无记录,成功,模拟30天外操作过");
		try {
			
			CreateThirdPartyUserReq createThirdPartyUserReq = JUserCallService.initCreateThirdUserReq();
			CreateThirdPartyUserCall createThirdPartyUserCall=new CreateThirdPartyUserCall();
			createThirdPartyUserReq
					.setHeadimgurl("http://wx.qlogo.cn/mmopen/uI5pczeERTY36SclJhUtdDRPN6adUrxvjIWtYyK7MtM58zHxYqcbk8hFib2mXic2rTocOlI4ib43QUx1iayZDzJxoicVR7ibiaqKqGn/0");
			createThirdPartyUserCall.setData(createThirdPartyUserReq);
			createThirdPartyUserCall.callService();
			Logger.verifyEquals("true", createThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", createThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
			Integer uid = createThirdPartyUserCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
			JUserCallService.UpdateLoginPwd(uid, "654321a");
			JUserCallService.UpdateTradingPwd(uid, "654321b");
			JUserCallService.resetMobile(uid, createThirdPartyUserReq.getMobile(), TestDataManager.getPhoneNum());
			JUserCallService.resetMail(uid, TestDataManager.getEmail());
			JUserWapper JUserWapper = new JUserWapper();
			JUserWapper.updateUserinfoUpdaterecordTime(uid, "2017-01-31");
			JUserWapper.updateThirdpartyUserbindHistoryTime(uid, "2017-01-31");
			ifcancloseaccountBean.setUserId(uid);
			ifcancloseaccountCall.setData(ifcancloseaccountBean);
			ifcancloseaccountCall.callService();
			Logger.verifyEquals("true", ifcancloseaccountCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", ifcancloseaccountCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", ifcancloseaccountCall.getString("Result"), "验证Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}